Uec3.QuotationQueryWin=Ext.extend(Ext.UecWindow,{	
	loadNum:0,
	searchPar:{},
	constructor:function(config){
		this.ajax=Uec3.App.Uec3Ajax;
		this.publicanLevelCombo=this.createPublicanLevelCombo({width:150});
		this.publicanLevelCombo_grid=this.createPublicanLevelCombo({width:150});
		this.sourceCombo_grid=this.createSourceCombo();
		this.sourceCombo=this.createSourceCombo();
		this.searchButton=new Ext.Button({
		width:80,
		text:'查  询',
		iconCls:'icon-search',
		style:'margin:20px 0px 0px 80px;',
		handler:this.funSearch.createDelegate(this)});
		this.formPanel=new Ext.FormPanel({
			width : 200,
			border:false,
	      	style:'padding-left:20px',
	      	defaults:{hideLabel:true},
	      	items:[
	      	  {xtype:'checkbox',name:'publicanLevelCheckbox',boxLabel:'公开级别',margins:'0 0 5 20'},
	      	  this.publicanLevelCombo,
              {xtype:'checkbox',name:'codeCheckbox',boxLabel:'编码',margins:'0 0 5 0'},
              {xtype:"textfield",name:'code',width:150},
              {xtype:'checkbox',name:'nameCheckbox',boxLabel:'名称',margins:'0 0 5 0'},
              {xtype:"textfield",name:'name',width:150},
              {xtype:'checkbox',name:'sourceCheckbox',boxLabel:'来源',margins:'0 0 5 0'},
              this.sourceCombo,
              {xtype:'checkbox',name:'brandCheckbox',boxLabel:'品牌',margins:'0 0 5 0'},
	      	  {xtype:"textfield",width:150,name:'brand'},
	      	  {xtype:'checkbox',name:'carModelCheckbox',boxLabel:'车型',margins:'0 0 5 0'},
	      	  {xtype:"textfield",width:150,name:'carModel'},
	      	  {xtype:'checkbox',name:'originCheckbox',boxLabel:'产地',margins:'0 0 5 0'},
	      	  {xtype:"textfield",width:150,name:'origin'},
	      	  {xtype:'checkbox',name:'onHandCheckbox',boxLabel:'显示无库存零件',margins:'0 0 5 0',checked:true},
	      	  this.searchButton,
	      	  {xtype:'hidden',name:'onHand',value:1}
	      	]
		});
		this.westPanel = new Ext.Panel({
			title : '零件模糊查询',
			region : 'west',
			split : true,
			width : 200,
			minSize : 200,
			maxSize : 200,
			collapsible : true,
			lines : false,
			layout:'fit',
			margins : '3 0 3 3',
			cmargins : '3 3 3 3',
			items : [this.formPanel]
		});
		this.northPanel = new Ext.Panel({
			region : 'north',
			height:40,
			layout:'uec3Grid',
			layoutConfig:{
				hGrid:[100],
				vGrid:[55,45]
			},
			items : [{
				xtype:'label',
				style:'font-weight:bold;font-size:18px;font-family:FangSong_GB2312',
				text:"我的零件和报价"
			},{
			xtype:'label',
			style:'font-weight:bold;font-size:14px;color:red;margin-left:40px',
			text:"以下情况将导致您的报价不能被其他公司搜索到:1.您未购买套餐。2.库存数为零。3.不公开的零件记录。4.报价数大于二十或为零 。"
			}]
		});
		var	partProperty_ds = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
					url : Uec3.App.Constants.homeUrl+'/part/extList.do'
		    }),
			pruneModifiedRecords : true,
			baseParams : {
				start : 0,
				limit :10
			},
			reader : new Ext.data.JsonReader({
						totalProperty : 'totalProperty',
						root : 'root'
					}, [
								{
								name : 'id'
							}, {
								name : 'companyId'
							}, {
								name : 'partId'
							}, {
								name : 'code'
							}, {
								name : 'source'
							},{
								name : 'name'
							}, {
								name : 'nameEn'
							}, {
								name : 'pyCode'
							}, {
								name : 'measurementUnit'
							}, {
								name : 'partCategoryId'
							}, {
								name : 'level1Name'
							}, {
								name : 'level2Name'
							}, {
								name : 'level1Id'
							}, {
								name : 'durability'
							}, {
								name : 'cost'
							}, {
								name : 'minPrice'
							},{
								name : 'insurancePrice'
							}, {
								name : 'maxOnHand'
							}, {
								name : 'minOnHand'
							}, {
								name : 'onHand'
							}, {
								name : 'onWay'
							}, {
								name : 'publicanLevel'
							}, {
								name : 'swapCode'
							}, {
								name : 'gmtCreate'
							}, {
								name : 'gmtModify'
							}, {
								name : 'isDelete'
							}, {
								name : 'brand'
							},{
								name : 'retailPrice'
							}, {
								name : 'carModel'
							}, {
								name : 'origin'
							}, {
								name : 'quotationQty'
							},{name:"sourceName"}
							,{name:"publicanLevelName"},{
								name : 'gmtLastQuotation',
								dateFormat:'Y-m-d H:i:s'
							}, {
								name : 'gmtLastSold',									
								dateFormat:'Y-m-d H:i:s'
							}]),
			remoteSort : true,

			// 默认排序字段
			sortInfo : {
				field : "id",
				direction : "asc"
			}

		});
		this.checkboxModel = new Ext.grid.CheckboxSelectionModel({
			moveEditorOnEnter : true,
			singleSelect : false,
			listeners:{
				'rowselect':this.funRowSelect.createDelegate(this)
			}
		});
		var partProperty_colModel = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
				this.checkboxModel,{
				header : "操作",
				xtype:'anchorcolumn',
				width : 100,
				dataIndex : 'act',
				items:[{
					text:"查看",
					scope:this,
					permissionId:25,
					handler:this.funBrowsePartProperty
				},{
					text:"编辑",
					scope:this,
					permissionId:26,
					handler:this.funEditPartProperty
				}]
				
				}, {
				header : "编码",
				width : 180,
				dataIndex : 'code',
				css : 'background-color: #ddd;'
				},{
				header : "名称",
				width : 180,
				dataIndex : 'name',
				css : 'background-color: #ddd;'
				}, {
				header : "来源",
				width : 80,
				dataIndex : 'source',
				css : 'background-color: #ddd;',
				renderer : Ext.util.Format.comboRenderer(this.sourceCombo)
				},{
				header : "品牌",
				width : 80,
				sortable : true,
				dataIndex : 'brand',
				css : 'background-color: #ddd;'
				}, {
				header : "车型",
				width : 80,
				dataIndex : 'carModel',
				css : 'background-color: #ddd;'
				},{
				header : "产地",
				width : 80,
				sortable : true,
				dataIndex : 'origin',
				css : 'background-color: #ddd;'
				}, {
				header : "平均成本",
				width : 80,
				dataIndex : 'cost',
				align : 'right',
				css : 'background-color: #ddd;'
				}, {
				header : "媒体价",
				align : 'right',
				width : 80,
				dataIndex : 'retailPrice',
				editor : new Ext.form.NumberField({
							allowBlank : false,
							allowNegative : false,
							decimalPrecision:2
				})
				}, {
				header : "保险价",
				width : 80,
				align : 'right',
				dataIndex : 'insurancePrice',
				editor : new Ext.form.NumberField({
							allowBlank : false,
							allowNegative : false,
							decimalPrecision:2
						})
				}, {
				header : "公开级别",
				width : 100,
				dataIndex : 'publicanLevel',
				editor:this.publicanLevelCombo_grid,
				renderer : Ext.util.Format.comboRenderer(this.publicanLevelCombo_grid)
				}, {
				header : "上架数量",
				width : 60,
				dataIndex : 'quotationQty',
				align : 'right',
				editor : new Ext.form.NumberField({
							allowBlank : false,
							allowNegative : false
						})
				}, {
				header : "库存总数",
				width : 60,
				dataIndex : 'onHand',
				css : 'background-color: #ddd;',
				align : 'right'
				}, {
				header : "最近交易时间",
				width : 130,
				dataIndex : 'gmtLastQuotation',
				css : 'background-color: #ddd;'
				}

		]);
		this.buttonpanel=new Ext.Toolbar({
			buttonAlign : 'center',
			/*height:30,
			split: false,
			cls:'x-panel',
			frame : true,
			defaultType:'button',*/
			items:['-',{
			text:'增加零件',
			iconCls: 'icon-add',
			handler :this.funAddPartProperty.createDelegate(this)
			},{
			text:'出入库查询',
			iconCls: 'icon-search',
			handler :this.funSearchSaleAndInventory.createDelegate(this)
			},{
			text:'库存查询',
			iconCls: 'icon-search',
			handler :this.funSearchInventory.createDelegate(this)
			},'-',{
			text:'全选',
			iconCls: 'icon-selectAll',
			handler :this.funSelectAll.createDelegate(this)
			},{
			text:'公开',
			iconCls: 'icon-publicanAll',
			handler : this.funPublican.createDelegate(this)
			},{
			text:'仅客户可见',
			iconCls: 'icon-publicanPartner',
			handler : this.funPublicanCustomer.createDelegate(this)
			},{
			text:'不公开',
			iconCls: 'icon-publicanNo',
			handler : this.funNoPublican.createDelegate(this)
			},{
			text:'报价保存',
			iconCls: 'icon-save',
			handler :this.funSave.createDelegate(this)
			},"-"]
		});
		
		this.partProperty_grid=new Ext.grid.EditorGridPanel({
			iconCls : 'icon-grid',
			region:"center",
			title:'零件属性',
			split: true,
			enableColumnMove : false,
			enableColumnMoveResize : false,
			stripeRows : true,
			clicksToEdit : 1,
			loadMask : {msg : "...加载数据中"},
			store : partProperty_ds,
			cm : partProperty_colModel,
			sm : this.checkboxModel,
			viewConfig : {
				// forceFit : true,
				columnsText : '显示的列',
				scrollOffset : 30,
				sortAscText : '升序',
				sortDescText : '降序'
			},
			tbar:this.buttonpanel,
			bbar : new Ext.PagingToolbar({
						pageSize:20,
						store : partProperty_ds,
						displayInfo : true,
						display : true,
						displayMsg : '第 {0} - {1} 条  共 {2} 条',
						emptyMsg : "没有记录"									
			}),listeners : {
				'afteredit':function(o){
					var value=o.value;
					var record=o.record;
					var field=o.field;
					if(field=='quotationQty'){
						if(value<0||value>20){
						record.set("quotationQty",1);
						record.commit();
						}
					}
					
				}
			}

		});	
		
		var	inventory_ds = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+'/inventory/browse_inventory!extList.do'}),
			pruneModifiedRecords : true,
			baseParams : {partId:0,start : 0,limit :10},
			reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, 
				[{name : 'id'}, {name : 'companyId'}, {name : 'storeId'},{name : 'shelf'},{name : 'partId'}, 
				{name : 'code'}, {name : 'source'}, {name : 'name'}, {name : 'nameEn'}, {name : 'pyCode'}, 
				{name : 'measurementUnit'}, {name : 'partCategoryId'}, {name : 'level1Name'}, {name : 'level2Name'}, 
				{name : 'level1Id'}, {name : 'durability'}, {name : 'brand'}, {name : 'origin'}, {name : 'cost'},
				{name : 'retailPrice'}, {name : 'insurancePrice'}, {name : 'minPrice'}, {name : 'initQuantity'},
				{name : 'onHand'}, {name : 'publicanLevel'}, {name : 'gmtEntry'}, {name : 'gmtModify'}, {name : 'documentType'},
				{name : 'documentId'}, {name : 'documentCode'}, {name : 'partnerId'},{name : 'inventoryIdBySeller'}, 
				{name : 'partnerName'}, {name : 'tmsVersion'},{name : 'gmtLastQuotation',dateFormat:'Y-m-d H:i:s'}, 
				{name : 'gmtLastSold',dateFormat:'Y-m-d H:i:s'}, {name : 'carModel'},{name:'storeName'}]),
			remoteSort : true,
			// 默认排序字段
			sortInfo : {field : "id",direction : "asc"}
		});
		var inventory_colModel = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
				header : "产地",
				width : 150,
				align : 'left',
				dataIndex : 'origin'
				},{
				header : "进价",
				align : 'right',
				width : 80,
				dataIndex : 'cost'
				},{
				header : "库存数量",
				width : 80,
				align : 'right',
				dataIndex : 'onHand'
				},{
				header : "仓库名称",
				width : 130,
				dataIndex : 'storeName'
				},{
				header : "进货时间",
				width : 130,
				dataIndex : 'gmtEntry'
				},{
				header : "供应商",
				width : 200,
				align : 'left',
				dataIndex : 'partnerName'
				},{
				header : "单据号",
				width : 120,
				align : 'left',
				dataIndex : 'documentCode'
				},{
				header : "进货数量",
				width : 80,
				align : 'right',
				dataIndex : 'initQuantity'
				},{
				header : "最近交易时间",
				width : 130,
				dataIndex : 'gmtLastSold'
				}

		]);
		this.inventory_grid=new Ext.grid.GridPanel({
			iconCls : 'icon-grid',
			title:'零件的库存记录',
			region:'south',
			enableColumnMove : false,
			enableColumnMoveResize : false,
			height:200,
			stripeRows : true,
			clicksToEdit : 1,
			loadMask : {
				msg : "...加载数据中"
			},
			store : inventory_ds,
			cm : inventory_colModel,
			viewConfig : {
				columnsText : '显示的列',
				scrollOffset : 10,
				sortAscText : '升序',
				sortDescText : '降序'
			},
			bbar : new Ext.PagingToolbar({
				pageSize : 6,
				store : inventory_ds,
				displayInfo : true,
				display : true,
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录"									
			})
		});	
		this.centerPanel=new Ext.Panel({
			region : 'center',
			activeTab : 0,
			layout:'border',
			defaults: {
			    //collapsible: true
				bodyStyle: 'padding:2px',
			   split: true
			},
			margins : '3 3 3 0',
			items:[this.partProperty_grid,this.inventory_grid]
		});
		config=Ext.apply(config||{},{items:[this.centerPanel,this.northPanel,this.westPanel]});
		Uec3.QuotationQueryWin.superclass.constructor.call(this,config);
	},
   //private
	initComponent:function(){
		Uec3.QuotationQueryWin.superclass.initComponent.call(this);
		this.initPartPropertySearchWindow();
		this.initEvent();
	},
	createCodeCombo:function(config){
		var ds_code_select = new Ext.data.JsonStore(
		{url:Uec3.App.Constants.homeUrl+"/part/getCodeByCompanyIdWithPage.do",root:'root',totalProperty:'totalProperty',fields:[{name:'code',type:'string'}]});
	 	config=Ext.apply(
	 	{name : 'code',fieldLabel:'零件编码',valueField:'code',displayField : 'code',mode : 'remote',
		 queryParam :'queryParam',queryDelay:500,minChars :2,store : ds_code_select,pageSize:10,selectOnFocus : true,
		 triggerAction : 'all',loadingText : '加载中...',listWidth:270
		},config||{});
	 	var combo=new Ext.form.ComboBox(config);
	 	return combo;
	},
	createPublicanLevelCombo:function(config){
		config=Ext.apply({hiddenName : 'publicanLevel'},config||{});
		var combo=Uec3.App.dictionary.getCombo("partproperty_publicanLevel",config);
	 	return combo;
	},
	createSourceCombo:function(config){
		config=Ext.apply({hiddenName : 'source'},config||{});
		var combo=Uec3.App.dictionary.getCombo("part_source",config);
	 	return combo;
	},
	initPartPropertySearchWindow:function(){
		var codeCombo=this.createCodeCombo();
	 	var ds_publicanLevel_select=Uec3.App.dictionary.getCombo('partproperty_publicanLevel',{
		   name : 'publicanLevel',
		   fieldLabel:'公开级别',
		   showWhole:true,
		   readOnly:true,
		   emptyText:"",
		   style:{background:'#dddddd'},
		   hiddenName:'publicanLevel'
		});
		//ds_publicanLevel_select.getStore().load();
		this.ds_source_select=Uec3.App.dictionary.getCombo('part_source', {
			 fieldLabel:'零件来源',
			 hiddenName:'source',
			 showBlank:true,
			 allowBlank : true,
		     editable:false,
             //emptyText : '请选择零件来源',
             focusOrder:2
  		});
  		//ds_source_select.getStore().load();
		this.partPropertySearchForm=new Ext.FormPanel({
			frame:true,
			height:150,
			region:"north",
    		border:false,
    		labelAlign:'right',
    		labelWidth:52,	     
    	    items:[
    	     	{
    	       			  layout:'column',
    	       			  items:[
    	       			  	{
    	       			  		columnWidth:.33,
    	       			  		layout:'form',
    	       			  		defaults:{anchor:'99%'},
    	       			  		items:[
    	       			  			codeCombo,{
    	       			  			   xtype:'textfield',				    
									   allowBlank : true,
									   blankText : '零件名称不能为空',
					                   name : 'name',
					                   fieldLabel:'零件名称',
					                   readOnly:true,
					                   style:{background:'#dddddd'}
    	       			  			},{
    	       			  			   xtype:'textfield',
    	       			  			   name:'carModel',
    	       			  			   fieldLabel:'车型'	,
    	       			  			   readOnly:true,
    	       			  			   style:{background:'#dddddd'},
    	       			  			   focusOrder:3
    	       			  			},ds_publicanLevel_select,{
    	       			  				xtype:'datefield',
    	       			  				name:'gmtStart',
    	       			  				format:'Y-m-d H:i:s',
    	       			  				fieldLabel:'开始时间'
    	       			  			}
    	       			  		]
    	       			  	},{
    	       			  		columnWidth:.33,
    	       			  		layout:'form',
    	       			  		defaults:{anchor:'99%'},
    	       			  		items:[
    	       			  		  this.ds_source_select,{
    	       			  	    	  xtype:'textfield',				    									
							          name : 'measurementUnit',
					                  fieldLabel:'单位',
					                  readOnly:true,
					                  style:{background:'#dddddd'}
    	       			  	       },{
    	       			  		     xtype:'textfield',
									 name : 'brand',
									 readOnly:true,
					                 style:{background:'#dddddd'},
					                 fieldLabel:'品牌',
					                 focusOrder:4
    	       			  		   },{
    	       			  		     xtype:'numberfield',
									 name : 'retailPrice',
									 fieldLabel:'媒体价',
									 allowBlank: false,
									 readOnly:true,
									 style:{background:'#dddddd'},
	                				 allowNegative: false,
	                				 focusOrder:6
    	       			  		   },{
    	       			  				xtype:'datefield',
    	       			  				name:'gmtEnd',
    	       			  				format:'Y-m-d H:i:s',
    	       			  				fieldLabel:'结束时间'
    	       			  			}
    	       			  		]
    	       			  	},{
    	       			  		columnWidth:.33,
    	       			  		layout:'form',
    	       			  		defaults:{anchor:'99%'},
    	       			  		items:[{
    	       			  			   xtype:'numberfield',
									   name : 'minPrice',
									   fieldLabel:'最低价',
									   readOnly:true,
									   //allowBlank: true,
									   style:{background:'#dddddd'},
	                				   allowNegative: false,
	                				   focusOrder:7
    	       			  			},{
    	       			  		   	 xtype:'numberfield',
									 name : 'insurancePrice',
									 fieldLabel:'保险价',
									 readOnly:true,
									 style:{background:'#dddddd'},
									 allowBlank: false,
	                                 allowNegative: false,
	                                 focusOrder:8
    	       			  		   },{
    	       			  		   	xtype:'textfield',
    	       			  		   	name:'onHand',
    	       			  		   	fieldLabel:'库存数',
    	       			  		   	readOnly:true,
									allowBlank: true,
									style:{background:'#dddddd'}
    	       			  		   	
    	       			  		   },{
    	       			  		   	xtype:'textfield',
    	       			  		   	name:'quotationQty',
    	       			  		   	fieldLabel:'上架数',
    	       			  		   	readOnly:true,
									allowBlank: true,
									style:{background:'#dddddd'}
    	       			  		   },{
    	       			  		   layout:'hbox',
    	       			  		   items:[{
    	       			  		   xtype:'button',
    	       			  		   		text:'查找',
    	       			  		   		anchor:'50%',
    	       			  		   		width:80,iconCls : 'icon-save',
    	       			  		   		style:{marginLeft:'56px'},
    	       			  		   		handler:this.funPartSearch.createDelegate(this)
    	       			  		   		},{
    	       			  		   		xtype:'button',
    	       			  		   		text:'清空',
    	       			  		   		anchor:'50%',
    	       			  		   		width:80,iconCls : 'icon-clear',
    	       			  		   		style:{marginLeft:'100px'},
    	       			  		   		handler:function(){
    	       			  		   			var form=this.partPropertySearchForm.form;
    	       			  		   			form.reset();
    	       			  		   			form.el.dom.reset();
    	       			  		   		}.createDelegate(this)
    	       			  		   		}
    	       			  		   ]}
    	       			  		]
    	       			  	}
    	       			  ]
    		}]
		});
		this.partPropertySearchTabPanel=new Ext.TabPanel({
			//anchor:'100% 70%',
			region:"center",
			//activeTab: 0,
			items:[
			   {
			   	title : '采购入库',
				iconCls: 'iconn-tab-receiveItem',
				layout:"fit",
				itemId:'receiveItem_tab',
				items : [this.getReceiveItemGrid.createDelegate(this)()]
			   },{
			   	title : '采购退货',
				iconCls: 'iconn-tab-returnedItem',
				layout:"fit",
				itemId:'returnedItem_tab',
				items : [this.getReturnedItemGrid.createDelegate(this)()]
			   },{
			   	title : '销售出库',
				iconCls: 'iconn-tab-saleItem',
				layout:"fit",
				itemId:'saleItem_tab',
				items : [this.getSaleItemGrid.createDelegate(this)()]
			   },{
			   	title : '销售退货',
				iconCls: 'iconn-tab-saleReturnedItem',
				layout:"fit",
				itemId:'saleReturnedItem_tab',
				items : [this.getSaleReturnItemGrid.createDelegate(this)()]
			   },{
			   	title : '急件',
				iconCls: 'iconn-tab-expressItem',
				layout:"fit",
				itemId:'expressItem_tab',
				items : [this.getExpressItemGrid.createDelegate(this)()]
			   }
			]
		});
		
		this.partPropertySearchWindow=new Ext.Window({
			layout:'border',
		    width:Ext.min([document.body.clientWidth*0.9,1000]),
		    height:Ext.min([document.body.clientHeight*0.9,530]),
		    closeAction:'hide',
		   	//autoHeight : true,
			iconCls : 'acc-icon',
		    //minWidth:1000,
			maximizable : true,
			resizable:false,
			maximized:false,
		    title:"零件入库出库查询",
			resizable :true,
			shadow : true,
			modal :true,
		    closable:true,
		    bodyStyle:'padding:5 5 5 5',
		    animCollapse:true,
			items : [this.partPropertySearchForm,this.partPropertySearchTabPanel]
		});
	},
	getReceiveItemGrid:function(){
		var receiveItem_browser_store=new Ext.data.JsonStore({
	 	   url:Uec3.App.Constants.homeUrl+"/receive/toReceive!fillReceiveItemBrowser.do",
			//params:{start:0,limit:2},
		   remoteSort :true,
		   root: "root",
           idProperty: "id",
           totalProperty: "totalProperty", 
           pruneModifiedRecords:true,
           fields:['codeOfBuyer','code','name','source','measurementUnit','orderQuantity','quantity','cost','retailPrice','minPrice','insurancePrice',
                   'publicanLevel','brand','origin','storeId','storeName','shelf','carModel']
	 	
	 	});
		var receiveItem_browser_grid = new Ext.grid.GridPanel({
			anchor:'100% 100%',
		    frame : false,
            columnLines :true,
            enableHdMenu : false,
            stripeRows: true,
            store:receiveItem_browser_store,
            autoWidth:true,
            //forceLayout :true,
            height:300,
            loadMask : {
				msg : '数据加载中...'
			},
   			viewConfig:
   			 {
   			   //autoFill:true,
      		   //forceFit:true,
               scrollOffset:20
             },	   	   
             autoScroll : true,
             layout:'fit',
             //defaults:{width:180},
	         columns:[	
	             new Ext.grid.RowNumberer(),
	            {header:'单据号',dataIndex:'codeOfBuyer',sortable:true,width:130},
	            {header:'零件编码',dataIndex:'code',sortable:true,width:130},
	            {header:'零件名称',dataIndex:'name',width:130},
	            {header:'车型',dataIndex:'carModel',width:110},
	            {header:'来源',dataIndex:'source',width:100,renderer:Ext.util.Format.comboRenderer(this.sourceCombo_grid)},
	            {header:'单位',dataIndex:'measurementUnit',width:110},
	            {header:'订购数量',dataIndex:'orderQuantity',width:120},
	            {header:'到货数量',dataIndex:'quantity',width:120},
	            {header:'进价',dataIndex:'cost',width:110},
	            {header:'媒体价',dataIndex:'retailPrice',width:110},
	            {header:'最低价',dataIndex:'minPrice',width:110},
	            {header:'保险价',dataIndex:'insurancePrice',width:110},
	            {header:'公开级别',dataIndex:'publicanLevel',width:130,renderer:Ext.util.Format.comboRenderer(this.publicanLevelCombo_grid)},
	            {header:'品牌',dataIndex:'brand',width:120},
	            {header:'产地',dataIndex:'origin',width:120},
	            {header:'仓库',dataIndex:'storeName',width:120},
	            {header:'仓位',dataIndex:'shelf',width:120}	
	         ],
	         bbar: new Ext.PagingToolbar({
	            pageSize:10,
                store:receiveItem_browser_store,
                displayInfo: true,
                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                emptyMsg: "没有记录"
	         })
		});
		return receiveItem_browser_grid;
	},
	getReturnedItemGrid:function(){
	  var returnedItem_browser_store=new Ext.data.JsonStore({
	 	   url:Uec3.App.Constants.homeUrl+"/returned/toReturned!fillReturnedItemBrowser.do",
		   remoteSort :true,
		   root: "root",
           idProperty: "id",
           totalProperty: "totalProperty", 
           pruneModifiedRecords:true,
           fields:['codeOfBuyer','code','name','source','measurementUnit','quantity','cost','costAmount','retailPrice','brand','origin','storeId','storeName','shelf','carModel'],
           listeners :{
             
           }
	 	
	 	});	 			
		var returnedItem_browser_grid = new Ext.grid.GridPanel({
		    frame : false,
            columnLines :true,
            height:408,                   
            enableHdMenu : false,
            stripeRows: true,
            store:returnedItem_browser_store,
            width : '100%',	   	   
   			viewConfig:{
                scrollOffset:20
            },
            
            autoScroll : true, 
            loadMask:{msg:'退库单明细加载中......'},
	        columns:[	
	         	new Ext.grid.RowNumberer(),
	            {header:'单据号',dataIndex:'codeOfBuyer',width:150},
	            {header:'零件编码',dataIndex:'code',width:150},
	            {header:'零件名称',dataIndex:'name',width:150},
	            {header:'车型',dataIndex:'carModel',width:110},
	            {header:'来源',dataIndex:'source', width:130,renderer:Ext.util.Format.comboRenderer(this.sourceCombo_grid)},
	            {header:'单位',dataIndex:'measurementUnit', width:110},
	            {header:'退货数量',dataIndex:'quantity',width:135},                         
                {header:'进价',dataIndex:'cost',width:135},
                {header:'退货金额',dataIndex:'costAmount',width:135},
                {header:'媒体价',dataIndex:'retailPrice',width:135},
	            {header:'品牌',dataIndex:'brand',width:135},
	            {header:'产地',dataIndex:'origin',width:135},
	            {header:'仓库',dataIndex:'storeName',width:150},
	            {header:'仓位',dataIndex:'shelf',width:135}	
	         ],
	         bbar: new Ext.PagingToolbar({
	            pageSize:10,
                store:returnedItem_browser_store,
                displayInfo: true,
                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                emptyMsg: "没有记录"
	         })
		});
		return returnedItem_browser_grid;
	},
	getSaleItemGrid:function(){
		var saleItem_browser_store=new Ext.data.JsonStore({
	 	    url:Uec3.App.Constants.homeUrl+"/sale/saleItemBrowser!fillSaleItemBrowser.do",
			remoteSort :true,
		    root: "root",
            idProperty: "id",
            totalProperty: "totalProperty", 
            pruneModifiedRecords:true,
            fields:['codeOfSeller','code','name','source','measurementUnit','quantity','cost','price','retailAmount','brand','origin','storeId','storeName','shelf','carModel']
	 	});
        var saleItem_browser_pagingToolBar = new Ext.PagingToolbar({
            pageSize:10,
            store:saleItem_browser_store,
            displayInfo: true,
            displayMsg: '第 {0} - {1} 条  共 {2} 条',
            emptyMsg: "没有记录"
        });
		var saleItem_browser_grid = new Ext.grid.GridPanel({
		    frame : false,
            columnLines :true,
            enableHdMenu : false,
            stripeRows: true,
            itemId:'saleItem_browser_grid',
            store:saleItem_browser_store,
            width : '100%',	   	   
   			viewConfig:{ 	   			   	
                scrollOffset:20
            },	   	   
            autoScroll : true, 	             
	        columns:[			           
	            {header:'单据号',dataIndex:'codeOfSeller',width:150},
	            {header:'零件编码',dataIndex:'code',width:150},
	            {header:'零件名称',dataIndex:'name',width:150},
	            {header:'车型',dataIndex:'carModel',width:120},
	            {header:'来源',dataIndex:'source', width:130,renderer:Ext.util.Format.comboRenderer(this.sourceCombo_grid)},
	            {header:'单位',dataIndex:'measurementUnit', width:110},
	            {header:'销售数量',dataIndex:'quantity',width:135},                         
                {header:'进价',dataIndex:'cost',width:135},
                {header:'售价',dataIndex:'price',width:135},
                {header:'销售金额',dataIndex:'retailAmount',width:135},
	            {header:'品牌',dataIndex:'brand',width:135},
	            {header:'产地',dataIndex:'origin',width:135},
	            {header:'仓库',dataIndex:'storeName',width:150},
	            {header:'仓位',dataIndex:'shelf',width:135}	
	         ],
	         bbar: new Ext.PagingToolbar({
	            pageSize:10,
                store:saleItem_browser_store,
                displayInfo: true,
                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                emptyMsg: "没有记录"
	         })
		});
		return saleItem_browser_grid;
	},
	getSaleReturnItemGrid:function(){
		var saleReturnItem_browser_store=new Ext.data.JsonStore({
	 	    url:Uec3.App.Constants.homeUrl+"/saleReturn/saleReturnItemBrowser!fillSaleReturnItemBrowser.do",
			remoteSort :true,
		    root: "root",
            idProperty: "id",
            totalProperty: "totalProperty", 
            pruneModifiedRecords:true,
            fields:['codeOfSeller','code','name','source','measurementUnit','saleQuantity','quantity','retailPrice','retailAmount','brand','origin','storeId','storeName','shelf','carModel']
	 	
	 	});
		var saleReturnItem_browser_grid = new Ext.grid.GridPanel({
			    frame : false,
                columnLines :true,
                enableHdMenu : false,
                stripeRows: true,
                store:saleReturnItem_browser_store,
                width : '100%',	   	   
  	   			viewConfig:{scrollOffset:20},	 
  	            loadMask : {msg : '销售退库明细加载中...'},
  	            autoScroll : true, 	             
		        columns:[			           
		            {header:'单据号',dataIndex:'codeOfSeller',width:150},
		            {header:'零件编码',dataIndex:'code',width:150},
		            {header:'零件名称',dataIndex:'name',width:150},
		            {header:'车型',dataIndex:'carModel',width:120},
		            {header:'来源',dataIndex:'source', width:130,renderer:Ext.util.Format.comboRenderer(this.sourceCombo_grid)},
		            {header:'单位',dataIndex:'measurementUnit', width:110},
		            {header:'销售数量',dataIndex:'saleQuantity',width:135}, 
		            {header:'退货数量',dataIndex:'quantity',width:135},                         
                    {header:'售价',dataIndex:'retailPrice',width:135},
                    {header:'退货金额',dataIndex:'retailAmount',width:135},                   
		            {header:'品牌',dataIndex:'brand',width:135},
		            {header:'产地',dataIndex:'origin',width:135},
		            {header:'仓库',dataIndex:'storeName',width:150},
		            {header:'仓位',dataIndex:'shelf',width:135}	
		         ],
		         bbar: new Ext.PagingToolbar({
		            pageSize:10,
	                store:saleReturnItem_browser_store,
	                displayInfo: true,
	                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                    emptyMsg: "没有记录"
		         })
		});
		return saleReturnItem_browser_grid;
	},
	getExpressItemGrid:function(){
		var expressItem_browser_store=new Ext.data.JsonStore({
	 	    url:Uec3.App.Constants.homeUrl+"/sale/saleItemBrowser!fillExpressItemBrowser.do",
			remoteSort :true,
		    root: "root",
            idProperty: "id",
            totalProperty: "totalProperty", 
            pruneModifiedRecords:true,
            fields:['codeOfSeller','code','name','source','measurementUnit','buyQuantity','saleQuantity','cost','retailPrice','retailAmount','brand','origin','storeId','storeName','shelf']	 	
	 	});
	 	var expressItem_browser_pagingToolBar = new Ext.PagingToolbar({
            pageSize:10,
            store:expressItem_browser_store,
            displayInfo: true,
            displayMsg: '第 {0} - {1} 条  共 {2} 条',
            emptyMsg: "没有记录"
        });
        var expressItem_browser_grid = new Ext.grid.GridPanel({
			    frame : false,
                columnLines :true,
                //height:408,                   
                enableHdMenu : false,
                stripeRows: true,
                store:expressItem_browser_store,
                width : '100%',	
                loadMask : {msg : '急件明细加载中...'},
  	   			viewConfig:{scrollOffset:20},	   	   
  	            autoScroll : true, 	             
		        columns:[			           
		            {header:'单据号',dataIndex:'codeOfSeller',width:150},
		            {header:'零件编码',dataIndex:'code',width:150},
		            {header:'零件名称',dataIndex:'name',width:150},
		            {header:'来源',dataIndex:'source', width:130,renderer:Ext.util.Format.comboRenderer(this.sourceCombo_grid)},
		            {header:'单位',dataIndex:'measurementUnit', width:110},
		            {header:'购入数量',dataIndex:'buyQuantity',width:135},   
		            {header:'销售数量',dataIndex:'saleQuantity',width:135},                         
                    {header:'进价',dataIndex:'cost',width:135},
                    {header:'售价',dataIndex:'retailPrice',width:135},
                    {header:'销售金额',dataIndex:'retailAmount',width:135},
		            {header:'品牌',dataIndex:'brand',width:130},
		            {header:'产地',dataIndex:'origin',width:130},
		            {header:'仓库',dataIndex:'storeName',width:150},
		            {header:'仓位',dataIndex:'shelf',width:130}	
		         ],
		         bbar: new Ext.PagingToolbar({
		            pageSize:10,
		            width:'100%',
	                store:expressItem_browser_store,
	                displayInfo: true,
	                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                    emptyMsg: "没有记录"
		         })
		});
		return expressItem_browser_grid;
	},
	funSave: function() {
		var _this=this;
		var modifyRecords=this.partProperty_grid.getStore().getModifiedRecords();
		if(modifyRecords.length>=1){
			var result=[];
			Ext.each(modifyRecords,function(record){
				result.push(record.data);
			});
			var q = Ext.encode(result); 
			this.ajax.request({
				url : Uec3.App.Constants.homeUrl+ '/part/savePartProperties.do',
				timeout:1800000,
				success : function(res) {
					var result = Ext.decode(res.responseText);
					if (result.success == "OK") {
						Ext.Msg.alert('提示', "保存成功");
						Ext.Msg.hide.defer(600,Ext.MessageBox);
						_this.partProperty_grid.getStore().commitChanges();
					
					} else {
						Ext.Msg.alert("提示", result.success);
                        _this.partProperty_grid.getView().refresh();
					}
				},
				params : {json : q}
		    });
		}else{
		   Ext.MessageBox.alert("提示","未有修改明细....");
		}					
	},
	funSelectAll:function(){
		this.checkboxModel.selectAll();
	},
	funPublican:function(){
		var records = this.checkboxModel.getSelections();
		if (records) {
			Ext.each(records, function(record) {
				record.set("publicanLevel", 0);
			});
		}
	},
	funNoPublican:function() {
		var records = this.checkboxModel.getSelections();
		if (records) {
			Ext.each(records, function(record) {
				record.set("publicanLevel", 2);
			});
		}
		this.partProperty_grid.getView().refresh();
	},
	funPublicanCustomer:function() {
		var records = this.checkboxModel.getSelections();
		if (records) {
			Ext.each(records, function(record) {
				record.set("publicanLevel", 1);
			});
			this.partProperty_grid.getView().refresh();
		}
	},
	funSearch:function(){
		var obj=this.formPanel.getForm().getValues();
		var checkboxs={};
		for(pro in obj){
			if(pro.indexOf("Checkbox")!=-1){
				var proObj=pro.substr(0,pro.length-8);
				checkboxs[proObj]=obj[proObj];
			}
		}
		this.partProperty_grid.getStore().baseParams.json=Ext.encode(checkboxs);
		this.partProperty_grid.getStore().load();
	},
	funSearchSaleAndInventory:function(){
		this.partPropertySearchWindow.show();
		
	},
	funPartSearch:function(){
		 var activeTab=this.partPropertySearchTabPanel.getActiveTab();
    	 if(activeTab){
    	 	this.funSearchAction.createDelegate(this)(activeTab);
    	 	this.searchPar=encodeFilte(this.partPropertySearchForm.form.getValues());
    	 }
	},
	funRowSelect:function(selectionModel,rowId,record){
		var selections=selectionModel.getSelections();
		if(selections.length==1){
			this.inventory_grid.getStore().baseParams={partId:record.data.partId};
			this.inventory_grid.setTitle("<span style='color:red'>"+record.data.name+"--"+record.data.code+"</span>"+"的零件库存记录");
			this.inventory_grid.getStore().load();
		}
	},
	funSearchWindowFillDetailForm:function(){
    },
    funPartSearchWindowResize:function(win,width,height){
    	var gridHeight=height-170;
		this.partPropertySearchTabPanel.setHeight(gridHeight);
		this.inventory_grid.setHeight(gridHeight*0.4);
		var partProperty_limit=parseInt((gridHeight*0.6-85)/22,10);
		
		this.partProperty_grid.getStore().baseParams.limit=partProperty_limit;
		var start=(this.partProperty_grid.getBottomToolbar().getPageData().activePage-1)*partProperty_limit;
		this.partProperty_grid.getStore().baseParams.start=start;
		this.partProperty_grid.getBottomToolbar().pageSize=partProperty_limit;
    },
	initEvent:function(){
		//this.sourceCombo_grid.getStore().load();
		//this.publicanLevelCombo_grid.getStore().load();
		//this.sourceCombo.getStore().load();
		this.partProperty_grid.getStore().on("beforeload",function(){
			this.resizeGridHeight(this.height);
		},this,{single:true});
		this.on('show',function(){
			this.partProperty_grid.getStore().load();
			this.partProperty_grid.on('afterlayout',function(){
			         this.resizeGridHeight.createDelegate(this)();
			},this);
			/*new Ext.ToolTip({
		        target: 'quotationToolTip',
		       // html: '如果您未购买套餐,您零件的报价将不能显示到首页!',
		        title: '注意事项',
		        //style:"font-size:30px;color:red",
		        items:[{
		         html: '如果您未购买套餐,您零件的报价将不能显示到首页!',
		         style:"font-size:30px;color:red"
		        }],
		        autoHide: true,
		        //closable: true,
		        draggable:true
		    });*/
		},this,{single:true});
		//this.on("resize",this.resize,this);
		this.partPropertySearchTabPanel.on('tabchange',this.funPartTabPanelActivate.createDelegate(this));
		this.partPropertySearchForm.getForm().findField('code').on('beforeselect',this.funPartPanelCodeCombo.createDelegate(this));
		this.partPropertySearchForm.getForm().findField('source').on('select',this.funPartPanelSourceCombo.createDelegate(this));
		this.partPropertySearchWindow.on('show',function(){
			var selections=this.checkboxModel.getSelections();
			if(selections.length>=1){
				this.partPropertySearchForm.getForm().loadRecord(selections[0]);
			}
			this.partPropertySearchTabPanel.setActiveTab(0);
			var activeTab=this.partPropertySearchTabPanel.getActiveTab();
			activeTab.get(0).getStore().load();
			this.searchPar=encodeFilte(this.partPropertySearchForm.form.getValues());
			
		},this);
		//this.partPropertySearchWindow.on('show',this.funPartSearchWindowResize);
	},
	validateParams:function(tab){
		var sp=this.searchPar;
		for(o in tab.searchParams){
			if(tab.searchParams[o]!=sp[o]){
				return false;
			}
		}
		return true;
	},
	funPartTabPanelActivate:function(panel,tab){
		if(!tab.searchParams||!this.validateParams(tab)){
			this.funSearchAction.createDelegate(this)(tab);
		}
	},
	funSearchAction:function(tab){
		var store=tab.get(0).getStore();
		var values=encodeFilte(this.partPropertySearchForm.form.getValues());
	    store.baseParams={searchJson:Ext.encode(values)};
	    tab.searchParams=values;
    	store.load();
	},
	funPartPanelCodeCombo:function(combo,newValue,oldValue){
		var form=this.partPropertySearchForm.form;
		form.reset();
		form.findField('source').clearValue();
	},
	funAddPartProperty:function(){
		var desktop=Uec3.App.getDesktop();
		desktop.launchWindowByParam("partPropertyOperation",{type:'add'});
	},
	funBrowsePartProperty:function(grid, rowIndex, colIndex, item, e){
		var record=grid.getStore().getAt(rowIndex);
		var desktop=Uec3.App.getDesktop();
		desktop.launchWindowByParam("partPropertyOperation",{type:'view',data:record.data,fn:function(data){
			for(var fieldName in data){
				record.set(fieldName,data[fieldName]);
			}
			record.commit();
		}});
	},
	funEditPartProperty:function(grid, rowIndex, colIndex, item, e){
		var record=grid.getStore().getAt(rowIndex);
		var desktop=Uec3.App.getDesktop();
		desktop.launchWindowByParam("partPropertyOperation",{type:'edit',data:record.data,fn:function(data){
			for(var fieldName in data){
				record.set(fieldName,data[fieldName]);
			}
			record.commit();
		}});
		
	},
	funSearchInventory:function(){
		var desktop=Uec3.App.getDesktop();
		desktop.launchWindowByParam("inventory");
	},
	funPartPanelSourceCombo:function(combo,newValue,oldValue){
		var form=this.partPropertySearchForm.getForm();
		var codeValue=form.findField('code').getValue();
		if(Ext.isEmpty(newValue.data.varIndex))return;
		if(newValue!=oldValue&&codeValue){
			var source = form.findField("source").getValue();
			var code = form.findField("code").getValue();
		 	Ext.Ajax.request({
		        url :Uec3.App.Constants.homeUrl+"/part/query_partProperty!searchPartPropertyBySouAndCode.do",
		    params :{json:Ext.encode({code:code,source:source})},
		    method :"post",
		    callback :function(options,success,response){
		         
		    },
		    success:function(response,options){	                	 
		    	  var result = Ext.decode(response.responseText);
		    	  if(result&&result.partProperty){
		    	  	 var partProperty=result.partProperty;
		    	     form.setValues(partProperty);
		    	  }else{
		    	  	 this.partPropertySearchForm.getForm().reset();
		    	     Ext.MessageBox.alert("提示","无此零件!");
		    	     Ext.MessageBox.hide.defer(600,Ext.MessageBox);
		    	  }
		    }.createDelegate(this),
		    failure:function(response,options){
		          Ext.MessageBox.alert("提示","数据加载异常");
		        }
		 	});	    		 
		}
	},
	
	resizeGridHeight:function(winHeight){
		var partProperty_limit=Math.round((this.partProperty_grid.getHeight()-118)/23-0.5);
		var inventory_limit=Math.round((this.inventory_grid.getHeight()-118)/23-0.5);
		this.partProperty_grid.getStore().baseParams.limit=partProperty_limit;
		this.partProperty_grid.getStore().baseParams.start=start;
		var start=(this.partProperty_grid.getBottomToolbar().getPageData().activePage-1)*partProperty_limit;
		this.partProperty_grid.getBottomToolbar().pageSize=partProperty_limit;
		
	}
});
Uec3.QuotationQueryWindow= Ext.extend(Ext.app.Module, {
	id : 'quotationQuery',
	createWindow : function() {
		var desktop = Uec3.App.getDesktop();
		var module = this;
		var win = desktop.getWindow('quotationQuery');
		if (!win) {
			win = desktop.createWindow({
				id : 'quotationQuery',
				title : '报价列表',
				width : document.body.clientWidth ,
				height : document.body.clientHeight-25,
				iconCls : 'acc-icon',
				moduleId:module.id,
				shim : false,
				//animCollapse : false,
				constrainHeader : true,
				maximizable : true,
				taskbuttonTooltip : "报价列表",
				layout : "border"
				
			},Uec3.QuotationQueryWin);
		}
		win.show();
	}
});